home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10782 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  77 lines

  1. Path: ra.nrl.navy.mil!itd!cheng
  2. From: cheng@itd.itd.nrl.navy.mil (John Peng-yung Cheng)
  3. Newsgroups: comp.lang.c
  4. Subject: pointer-to-pointer usage
  5. Date: 19 Mar 1996 22:15:52 GMT
  6. Organization: Information Technology Division, Naval Research Laboratory
  7. Message-ID: <4inbmp$506@ra.nrl.navy.mil>
  8. NNTP-Posting-Host: itd.nrl.navy.mil
  9.  
  10. Greetings,
  11.  
  12.     Could someone explain the following warnings that I get when
  13. I compile with GNU compiler?  Please ignore the -D switches in the
  14. compiler statement; I am developing for vxWorks, but the OS should not
  15. make a difference.  Obviously, the functions do not do anything useful,
  16. but are just an extraction of my actual code.
  17.  
  18. cc68k -D__VX__ -I/usr/vw/h -I/export/home/cheng/spc/h -Wall -ansi -DCPU=MC68040 -DCPU_SPEED=25MHz  -nostdinc -g -O2 -c test.c
  19. test.c: In function `call_change':
  20. test.c:34: warning: passing arg 1 of `change_ptr' from incompatible pointer type
  21. test.c:35: warning: passing arg 1 of `change_ptr' from incompatible pointer type
  22. test.c:36: warning: passing arg 1 of `change_ptr' from incompatible pointer type
  23. test.o completed
  24.  
  25. In particular, the first four function calls to change_ptr() are 
  26. equivalent, but only the last one does not generate a warning.  Also,
  27. the declaration and usage of change_ptr_2 does not generate any warnings.
  28.  
  29. So my question is why should I have to put in an extra cast, and/or
  30. declare a pointer type to my structure just so that the compiler 
  31. will not generate these warnings?
  32.  
  33. Thanks in advance
  34.     John Cheng
  35.  
  36. test.c: 
  37. #include <stdlib.h>
  38.  
  39. typedef struct {
  40.         int     a;
  41.         char    b;
  42.         } tempType, *tempPtr;
  43.  
  44. /* test functions */
  45. int change_ptr(tempType **temp)
  46. {
  47. free(*temp);
  48. *temp = NULL;
  49. return 0;
  50. }
  51.  
  52. int change_ptr_2(tempPtr *temp)
  53. {
  54. free(temp);
  55. temp = NULL;
  56. return 0;
  57. }
  58.  
  59. id call_change (void)
  60. {
  61. tempType        *temp1;
  62. tempPtr         temp2;
  63.  
  64. temp1 = malloc (sizeof(tempType));
  65.  
  66. (*temp1).a = 1;
  67. (*temp1).b = 'a';
  68.  
  69. change_ptr(temp1);
  70. change_ptr(&(*temp1));
  71. change_ptr(&*temp1);
  72. change_ptr((tempType **)temp1);
  73. change_ptr_2(&temp2);
  74. }
  75. /* end of test.c */ 
  76.  
  77.